package com.bodu.util;

import org.apache.commons.lang3.StringUtils;

/**
 * @author Administrator
 */
public class ObjectTransitionUtils {

    public static void main(String[] args) {
        String table = captionLine("T_ADMIN");
        System.out.println(table);
    }

    /**
     * 生成文件名称 T_admin
     * @param msg
     * @return
     */
    public static String captionLine(String msg) {
        String[] sp = msg.split("_");
        StringBuffer stringBuffer = new StringBuffer("");
        for (String s: sp) {
            if (StringUtils.isNotEmpty(s)) {
                stringBuffer.append(StringUtils.capitalize(StringUtils.lowerCase(s)));
            }
        }
        return stringBuffer.toString();
    }

    public static String captionWordLowerLine (String msg) {
        String s = captionLine(msg);
        return StringUtils.uncapitalize(s);
    }

    /**
     *   aYmmmW  ==> a_ymmm_w
     * @return
     */
    public static String upperToLowerLine(String msg ) {
        //将需要处理的数据转换成大写数据
        StringBuffer sb = new StringBuffer("");

        for (char c : msg.toCharArray()) {

            if (c >= 'A' && c <= 'Z') {
                sb.append("_").append((char) (c + 32));
            } else {
                sb.append(c);
            }
        }
        return sb.toString();
    }

    public static String lowerToUpperLine(String msg){
        //将需要处理的数据转换成大写数据
        StringBuffer sb = new StringBuffer("");

        for (char c : msg.toCharArray()) {

            if (c >= 'a' && c <= 'z') {
                sb.append("_").append((char) (c - 32));
            } else {
                sb.append(c);
            }
        }
        return sb.toString();
    }
}
